package com.gxa.saas.sso.service.impl;


import com.gxa.saas.sso.service.SmsService;
import com.gxa.saas.sso.util.SendSms;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Service
@Transactional(rollbackFor = Throwable.class)
public class SmsServiceImpl implements SmsService {

    @Resource
    private RedisTemplate redisTemplate = null;

    public static final String LOGIN_SMS = "login_sms:";

    @Override
    public void sendLoginSms(String phone) throws Exception {
        String sysCode = SendSms.getMsgCode();
        System.out.println("sysCode:--------"+sysCode);
        redisTemplate.opsForValue().set(LOGIN_SMS+phone,sysCode,15, TimeUnit.MINUTES);
        String templateParam = "{\"code\":"+sysCode+"}";
//        SendSmsResponse response = SendSms.sendSms(phone, "SMS_204986028", templateParam);
//        System.out.println("短信接口返回的数据----------------");
//        System.out.println("Code=" + response.getCode());
//        System.out.println("Message=" + response.getMessage());
//        System.out.println("RequestId=" + response.getRequestId());
//        System.out.println("BizId=" + response.getBizId());
    }

}
